package com.yue.jersey.practice.provider;

import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

/**
 * Created by qiuyang on 16/02/2017.
 */
@Service
public class DefaultRetryProvider implements RetryProvider {
    @Retryable(value = {RuntimeException.class}, maxAttempts = 5, backoff = @Backoff(delay = 5000L, multiplier = 1))
    @Override
    public void retryTest() {
        System.out.println("do somethind ...");
        throw new RuntimeException("RuntimeException ...");
    }

    @Recover   //当重试到达指定次数时，被注解的方法将被回调，可以在该方法中进行日志处理。需要注意的是发生的异常和入参类型一致时才会回调
    @Override
    public void recover(RuntimeException e) {
        System.out.println(e.getMessage());
        System.out.println("recover ...");
    }
}
